-- @owner: @zou_jialiang050
-- @date: 2022/02/24
-- @testpoint: 在更新src表后触发向des表中插入计数器数字  each statement  expect 成功

--step1:建表;expect:成功
drop table if exists t_trigger_src_0041 cascade;
drop table if exists t_trigger_des_0041 cascade;
drop sequence if exists trigger_des_seq1 cascade;
create table t_trigger_src_0041(id1 int, id2 int, id3 int) with (storage_type=ustore);
create table t_trigger_des_0041(id1 int, id2 int, id3 int) with (storage_type=ustore);
create sequence trigger_des_seq1;

--step2:在更新src表后触发向des表中插入计数器数字 each statement;expect:成功
create or replace function tri_truncate_func() returns trigger as
$$
declare
begin
insert into t_trigger_des_0041 values(nextval('trigger_des_seq1'),nextval('trigger_des_seq1'),nextval('trigger_des_seq1'));
return new;
end
$$ language plpgsql;
/
drop trigger if exists truncate_trigger on t_trigger_src_0041;
create trigger truncate_trigger after update on t_trigger_src_0041
for each statement
execute procedure tri_truncate_func();
/
select * from t_trigger_des_0041 order by id1;
insert into t_trigger_src_0041 values(1,1,1),(2,2,2),(3,3,3);
select * from t_trigger_src_0041 order by id1;
select * from t_trigger_des_0041 order by id1;
update t_trigger_src_0041 set id1=100;
select * from t_trigger_src_0041 order by id1;
select * from t_trigger_des_0041 order by id1;

--step3:清理环境;expect:成功
drop table if exists t_trigger_src_0041 cascade;
drop table if exists t_trigger_des_0041 cascade;
drop sequence if exists trigger_des_seq1 cascade;